<!DOCTYPE html>
<html>
<head>
    {include file="public/header" /}
</head>
<body>
<div class="layuimini-container">
    <div class="layuimini-main">
        <form class="layui-form layui-form-pane" action="">
            <!--<fieldset class="table-search-fieldset">-->
                <!--<legend>搜索信息</legend>-->
                <div style="margin: 10px 10px 10px 10px">
                    <div class="layui-form-item">
                        <div class="layui-inline">
                            <label class="layui-form-label">卡券名称</label>
                            <div class="layui-input-inline">
                                <input type="text" name="title" placeholder="请输入卡券名称" autocomplete="off" class="layui-input">
                            </div>
                        </div>
                        <div class="layui-inline" style="display: none">
                            <button type="submit" class="layui-btn layui-btn-primary" lay-submit lay-filter="data-search-btn"><i class="layui-icon"></i> 搜 索</button>
                        </div>
                    </div>
                </div>
            <!--</fieldset>-->
        </form>
        <script type="text/html" id="toolbarDemo">
            <div class="layui-btn-container">
                <button class="layui-btn layui-btn-normal layui-btn-sm data-add-btn" lay-event="add">赠送卡券</button>
            </div>
        </script>
        <table class="layui-hide" id="currentTableId" lay-filter="currentTableFilter"></table>
        <input type="hidden" id="memberCode">
    </div>
</div>
{include file="public/footer" /}

<script>
    layui.use(['form', 'table', 'laydate'], function () {
        var $ = layui.jquery,
            form = layui.form,
            table = layui.table,
            laydate = layui.laydate;
        /*用户卡券*/
        table.render({
            elem: '#currentTableId',
            url: '/admin/Member/voucherInfo',
            method: 'post',
            where: {memberCode: "{$memberCode}"},
            parseData: function (res) { //res 即为原始返回的数据
                $('#memberCode').val(res.data.info.code);
                return {
                    "code": res.code, //解析接口状态
                    "msg": res.msg, //解析提示文本
                    "count": res.data.info.total, //解析数据长度
                    "data": res.data.info.data, //解析数据列表
                };
            },
            toolbar: '#toolbarDemo',
            defaultToolbar: ['filter', 'exports', 'print', {
                title: '提示',
                layEvent: 'LAYTABLE_TIPS',
                icon: 'layui-icon-tips'
            }],
            cols: [[
                {field: 'voucher_title', title: '卡券名称', sort: true, align: 'center'},
                {field: 'price', title: '价值', sort: true, align: 'center'},
                {field: 'expiration_time', title: '过期时间', sort: true, align: 'center'},
                {field: 'get_time', title: '获得时间', sort: true, align: 'center'}
            ]],
            limits: [10, 15, 20, 25, 30, 50, 100],
            limit: 10,
            page: true,
            skin: 'line,row',
            done: function (res, curr, count) {

            }
        });

        // 监听搜索操作
        form.on('submit(data-search-btn)', function (data) {
            var result = JSON.stringify(data.field);
            //执行搜索重载
            table.reload('currentTableId', {
                page: {
                    curr: 1
                }
                , where: {
                    searchParams: result
                }
            }, 'data');
            return false;
        });

        /*赠送卡券*/
        table.on('toolbar(currentTableFilter)', function (obj) {
            if (obj.event === 'add') {  // 监听添加操作
                var index = layer.open({
                    title: '赠送卡券',
                    type: 2,
                    shade: 0.2,
                    maxmin: true,
                    shadeClose: true,
                    area: ['100%', '100%'],
                    content: "/admin/Member/giveVoucher?action=view&code={$memberCode}",
                });
                $(window).on("resize", function () {
                    layer.full(index);
                });
            }
        });

    });
</script>

</body>
</html>